@tool
class_name ContextBehavior_AddLinearForceInterest
extends BaseContextBehavior

enum DirSpace
{
	Local,
	World,
}
#region 属性
@export var force:float
@export var dir_space:DirSpace
@export var angle:float
## 是否只在第一次执行转向计算
@export var only_once:bool = false
var interest = Vector2.RIGHT
var calced:bool = false
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
func init():
	super()
func calc_steering(behaviors_owner:Node,agent:SteeringBehaviorAgent,delta:float):
	super(behaviors_owner,agent,delta)
	if not only_once or (not calced and only_once):
		calced = true
		interest = Vector2.RIGHT
		match dir_space:
			DirSpace.Local:
				var root:Node2D = agent.get_entity_root()
				interest = interest.rotated(deg_to_rad(angle) + root.rotation)
			DirSpace.World:
				interest = interest.rotated(deg_to_rad(angle))
			_:
				interest = interest.rotated(deg_to_rad(angle))
	agent.add_vel_interest(interest * sensitive * force)
#endregion
#region 公共方法
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _init() -> void:
	if Engine.is_editor_hint():
		resource_local_to_scene = true
	behavior_type = GameEnum.ContextBehaviorType.AddLinearForceInterest
func draw() -> void:
	super.draw()
#endregion
